package com.macrovideo.custom;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.CountDownTimer;
import android.widget.TextView;

public class CountDownTextView extends CountDownTimer {  
    

	public static final int TIME_COUNT_FUTURE = 60000;  
    public static final int TIME_COUNT_INTERVAL = 1000;  
      
    private int nCount=0;
    private Context mContext;  
    private TextView mTextView;  
    private String mOriginalText;  
    private Drawable mOriginalBackground;  
    private Drawable mTickBackground;  
    private int mOriginalTextColor;  
      
    public CountDownTextView() {  
        super(TIME_COUNT_FUTURE, TIME_COUNT_INTERVAL);  
    }  
    public CountDownTextView(long millisInFuture, long countDownInterval) {
		super(millisInFuture, countDownInterval);
		// TODO Auto-generated constructor stub
	}
    
    public void init(Context context, TextView textView, int nCount) {  
    	this.nCount=nCount;
        this.mContext = context;  
        this.mTextView = textView;  
        this.mOriginalText = ""+this.nCount;  
        this.mOriginalBackground = mTextView.getBackground();  
        this.mTickBackground = this.mOriginalBackground;  
        this.mOriginalTextColor = mTextView.getCurrentTextColor();  
    }  
      
    public void setTickDrawable(Drawable tickDrawable) {  
        this.mTickBackground = tickDrawable;  
    }  
  
    @Override  
    public void onFinish() {  
        if (mContext != null && mTextView != null) {  
//            mTextView.setText(mOriginalText);  
//            mTextView.setTextColor(mOriginalTextColor);  
//            mTextView.setBackgroundDrawable(mOriginalBackground);  
//            mTextView.setClickable(true);  
        }  
    }  
  
    @Override  
    public void onTick(long millisUntilFinished) {  
        if (mContext != null && mTextView != null) {  
        	nCount--;
        	if(nCount<0)nCount=0;
        	try{
        		mTextView.setText(""+nCount); 
        	}catch(Exception e){
        		
        	}
             
        }  
    }  
}  
